<%--
  Created by IntelliJ IDEA.
  User: 19416
  Date: 2022-08-14
  Time: 10:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="JS/jquery-2.1.1.min.js"></script>
</head>
<body>
<form action="${pageContext.request.contextPath}/CardInsetServlet" method="get">
    <table border="1px">
        <tr>
            <td>持卡人姓名</td><td><input type="text" name="userName" id="userName"></td>
        </tr>
        <tr>
            <td>持卡人身份证</td><td><input type="text" name="idNumber" id="idNumber"><p id="span"></p></td>

        </tr>
        <tr>
            <td>办卡日期</td><td><input type="text" name="createDate" id="createDate"></td>
        </tr>
    </table>
    <p>
       <input type="submit" value="提交" id="btn">
    </p>
</form>
<script>

    $("#idNumber").blur(function (){
        var idNumber = $("#idNumber").val();
        $.get("${pageContext.request.contextPath}/CardIdNumberServlet","idNumber="+idNumber,function (data){
            $("#span").html("");
            if (data == "true"){
                $("#span").html("已持有卡");
            }
        })
    })


$("#btn").click(function (){
    var  userName = $("#userName").val();
    var  idNumber = $("#idNumber").val();
    var  createDate = $("#createDate").val();
    var isDate = /^\d{4}[-]\d{2}[-]\d{2}$/;

    if (userName.length == 0 || idNumber.length == 0 || createDate.length == 0) {
        alert("请完善门禁卡信息！")
        return false;
    }else if (!isDate.test(createDate)){
        alert("日期格式不正确！")
        return  false;
    }else {
        alert("添加成功")
        location.href="CardListServlet";
    }
})
</script>
</body>
</html>
